package com.base.cn.platform.os.controller.op.affiche;

import com.base.cn.platform.os.common.controller.BaseController;
import com.base.cn.platform.os.common.mybatis.Pagination;
import com.base.cn.platform.os.common.utils.StringUtils;
import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.entity.op.affiche.OpAffiche;
import com.base.cn.platform.os.service.op.affiche.OpAfficheBiz;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Map;

/**
 * 消息Controller
 * @author zsw
 * @create 2018/5/12
 */
@RestController
@RequestMapping("/manage/op")
public class OpAfficheController extends BaseController {

    @Autowired
    private OpAfficheBiz opAfficheBiz;

        /**
         * 查询消息列表
         * @param currentPage 分页
         * @param affiche 查询条件
         * @param subjectData 是否设置专业科目
         * @param courseData 是否设置课程
         * @param sysUserData 是否设置创建人
         * @return
         */
        @RequestMapping("/queryAjaxAfficheList")
        public PageInfo<OpAffiche> queryAjaxAfficheList(@RequestParam(value="currentPage",required = false,defaultValue = "1")int currentPage,
                                                        @RequestBody OpAffiche affiche,
                                                        @RequestParam(value = "subjectData",required = false,defaultValue = "false")boolean subjectData,
                                                        @RequestParam(value = "courseData",required = false,defaultValue = "false")boolean courseData,
                                                        @RequestParam(value = "sysUserData",required = false,defaultValue = "false")boolean sysUserData){
            Pagination affichePage = new Pagination();
            affichePage.setCurrentPage(currentPage);
            PageInfo<OpAffiche> affichePageInfo = opAfficheBiz.queryAfficheList(affichePage, affiche,subjectData,courseData,sysUserData);
            return affichePageInfo;
        }

        /**
         * 发布消息
         * @param affiche 消息实体
         * @return
         */
        @RequestMapping("/saveUpdateAffiche")
        public Map<String ,Object> saveUpdateAffiche(@RequestBody OpAffiche affiche){
            if (StringUtils.isEmpty(affiche.getContext())){
                return ResultUtil.ERROR("请填写发布内容");
            }
            opAfficheBiz.saveUpdateAffiche(affiche);
            return ResultUtil.SUCCESS("保存成功");
        }

        /**
         * 删除消息
         * @param afficheIds 消息Id串
         * @create 2018-05-12
         * @return
         */
        @RequestMapping("/deleteAffiche")
        public Map<String,Object> deleteAffiche(@RequestParam("afficheIds") String afficheIds){
            opAfficheBiz.deleteAffiche(afficheIds);
            return ResultUtil.SUCCESS("删除成功");
        }

        /**
         * 根据ID查询消息
         * @param id 消息id
         * @create 2018-05-12
         * @return
         */
        @RequestMapping("/findAfficheById")
        public OpAffiche findAfficheById(@RequestParam("id")BigDecimal id,
                                         @RequestParam(value = "subjectData",required = false,defaultValue = "false")boolean subjectData,
                                         @RequestParam(value = "courseData",required = false,defaultValue = "false")boolean courseData,
                                         @RequestParam(value = "sysUserData",required = false,defaultValue = "false")boolean sysUserData){
            return opAfficheBiz.findAfficheById(id,subjectData,courseData,sysUserData);
        }

        /**
         * 修改消息状态
         * @param afficheIds 消息id串
         * @param status 状态：0.正常 1.禁用 2.删除
         * @return
         */
        @RequestMapping("/updateAfficheStatusByIds")
        public Map<String, Object> updateAfficheStatusByIds(@RequestParam("afficheIds")String afficheIds,
                                                     @RequestParam("status") Integer status){
            opAfficheBiz.updateArticleStatusByIds(afficheIds, status);
            return ResultUtil.SUCCESS("修改成功");
        }
}
